import { defineStore } from "pinia";

import storage from "../../utils/storage.js";
import { login } from "../../service/modules/user.js";
import { encrypt } from "../../utils/crypto.js";
import { useRouter } from "vue-router";
console.log(`output->`, useRouter());
const useUserStore = defineStore({
  id: "app-user",
  state: () => {
    return {
      info: storage.get("current_admin") ?? {},
      token: storage.get("access_token") ?? "",
      opened: false,
    };
  },
  actions: {
    openedChange() {
      this.opened = !this.opened;
    },
    setInfo(info) {
      this.info = info;
      storage.set("current_admin", info);
    },
    setToken(token) {
      this.token = token;
      storage.set("access_token", token);
    },
    // async userLogin(data) {
    //   const router = useRouter();
    //   console.log("useRouter", useRouter);
    //   console.log(router);
    //   const res = await login({
    //     userName: data.account,
    //     password: encrypt(data.pwd),
    //   });
    //   if (res.data.code === 0) {
    //     this.setInfo(res.data.result);
    //     this.setToken(res.data.result.token);
    //     router.push("/odmInfo");
    //   }
    //   console.log(res);
    // },
  },
});
export default useUserStore;
